﻿using System;
using System.Linq.Expressions;
using System.Web.Mvc;

namespace CodeContrib.Web.Mvc
{
	public static class ExpressionInputExtensions
	{
		public static TProperty GetValue<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression) where TModel : class
		{
			var model = htmlHelper.ViewData.Model;

			if (model != null)
			{
				expression.Compile().Invoke(model);
			}

			return default(TProperty);
		}
	}
}